﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using WQDSkin.Forms.Component;
using WQDSkin.Forms.ValueBoxes;

namespace WQDSkin.Forms.Controls
{
    [DefaultEvent("CheckStateChanged")]
    [Localizability(LocalizationCategory.CheckBox)]
    public class WQDCheckBox: ToggleButton
    {
      
        static WQDCheckBox()
        {
            // Set the default Style
            DefaultStyleKeyProperty.OverrideMetadata(typeof(WQDCheckBox), new FrameworkPropertyMetadata(typeof(WQDCheckBox)));
            
            KeyboardNavigation.AcceptsReturnProperty.OverrideMetadata(typeof(WQDCheckBox), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox));

            //ControlsTraceLogger.AddControl(TelemetryControls.CheckBox);
        }

        public WQDCheckBox() : base()
        {
        }

      

        protected override AutomationPeer OnCreateAutomationPeer()
        {
            return new WQDCheckBoxAutomationPeer(this);
        }


        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            // Add aditional keys "+" and "-" when we are not in IsThreeState mode
            if (!IsThreeState)
            {
                if (e.Key == Key.OemPlus || e.Key == Key.Add)
                {
                    e.Handled = true;
                   
                    //DependencyProperty
                    this.ClearValue(IsPressedProperty);
                    this.SetCurrentValue(IsCheckedProperty, true); 
                }
                else if (e.Key == Key.OemMinus || e.Key == Key.Subtract)
                {
                    e.Handled = true;
                    this.ClearValue(IsPressedProperty);
                    SetCurrentValue(IsCheckedProperty, false);
                }
            }
        }

        protected override void OnAccessKey(AccessKeyEventArgs e)
        {
            if (!IsKeyboardFocused)
            {
                Focus();
            }

            base.OnAccessKey(e);
        }


        public SolidColorBrush IconColor
        {
            get { return (SolidColorBrush)GetValue(IconColorProperty); }
            set { SetValue(IconColorProperty, value); }
        }

        public static readonly DependencyProperty IconColorProperty =
            DependencyProperty.Register("IconColor", typeof(SolidColorBrush), typeof(WQDCheckBox),
                new PropertyMetadata(WQDSystemColors.ThemeBackground));
    }
}
